home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPPANS.ZIP / PUTLN.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  2KB  |  80 lines

  1. // putln.cpp -- Add putln function to cwindow class
  2.  
  3. #include <iostream.h>
  4. #include <dos.h>
  5. #include <conio.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include "window.h"
  9.  
  10. class cwindow2 : public cwindow {
  11.   private:
  12.     int yline;
  13.   public:
  14.     cwindow2() : cwindow() 
  15.       { yline = 0; }
  16.     cwindow2(winStruct &ws, const char *title) : cwindow(ws, title)
  17.       { yline = 0; }
  18.     void putln(char *s);
  19.     void gotorc(int row, int col);
  20. };
  21.  
  22. void fillBuffer(char *buf);
  23.  
  24. main()
  25. {
  26.   winStruct ws = { 4, 44, 31, 18, 0x07, 0x1f, 0x70, 3 };
  27.   cwindow2 *theWindow;
  28.   char buffer[80];
  29.  
  30.   cwindow::startup();
  31.   theWindow = new cwindow2(ws, " Scrolling Window ");
  32.   theWindow->showWindow();
  33.   while (!kbhit()) {
  34.     fillBuffer(buffer);
  35.     theWindow->putln(buffer);
  36.     delay(125);      // Remove this line for top speed
  37.   }
  38.   cwindow::shutDown();
  39. }
  40.  
  41. /* Write string and perform carriage return, line feed */
  42. void cwindow2::putln(char *s)
  43. {
  44.   winStruct ws;
  45.  
  46.   puts(s);
  47.   ws = getInfo();
  48.   int n = ws.height - 2;
  49.   if (yline > n) yline = n;
  50.   if (yline == n) {
  51.     scrollUp(1);
  52.     gotorc(yline, 0);
  53.     eeol();
  54.   } else
  55.     gotorc(++yline, 0);
  56. }
  57.  
  58. /* -- Replacement gotorc function */
  59. void cwindow2::gotorc(int row, int col)
  60. {
  61.   yline = row;
  62.   cwindow::gotorc(row, col);
  63. }
  64.  
  65. /* -- Fill character buffer with random letters */
  66. void fillBuffer(char *buf)
  67. {
  68.   for (int i = 0; i <= 20; i++)
  69.     buf[i] = 'a' + (rand() % 26);
  70.   buf[i] = 0;
  71. }
  72.  
  73.  
  74. // Copyright (c) 1990 by Tom Swan. All rights reserved
  75. // Revision 1.00    Date: 12/05/1990   Time: 06:10 pm
  76.  
  77. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  78. // Converted for Borland C++ 2.0
  79.  
  80.